/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormularioProfesor.java
 *
 * Created on 19/02/2011, 03:49:33 PM
 */

package vistas;

import clases.Profesor;
import clases.Seccion;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author 
 */
public class FormularioProfesor extends javax.swing.JFrame {

     private Seccion seccion;


    public void setSeccion(Seccion seccion) {
        this.seccion = seccion;
    }


    /** Creates new form FormularioProfesor */
    public FormularioProfesor() {
        initComponents();
    }


    public void cancelar(){
        txtApe.setText("");
        txtCed.setText("");
        txtNom.setText("");
        txtTit.setText("");
    }

      public boolean validarVacios(){
        if(txtApe.getText().equals(""))
                return false;
        else if(txtNom.getText().equals(""))
                return false;
        else if(txtCed.getText().equals(""))
                return false;
            else
                return true;
   }

   public boolean validarCedula(){
        try {
            if(Integer.parseInt(txtCed.getText())>0)
                return true;
            else
                return false;
	} catch (NumberFormatException e) {
            return false;
        }
   }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtCed = new javax.swing.JTextField();
        txtNom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtApe = new javax.swing.JTextField();
        btnAsignar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        txtTit = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel1.setText("Cedula:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(50, 30, 110, 18);

        txtCed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCedActionPerformed(evt);
            }
        });
        getContentPane().add(txtCed);
        txtCed.setBounds(180, 20, 90, 28);
        getContentPane().add(txtNom);
        txtNom.setBounds(180, 70, 90, 28);

        jLabel2.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel2.setText("Nombre:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(50, 80, 90, 18);

        jLabel3.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel3.setText("Apellido:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(50, 130, 100, 18);
        getContentPane().add(txtApe);
        txtApe.setBounds(180, 120, 90, 28);

        btnAsignar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnAsignar.setText("Asignar");
        btnAsignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAsignarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAsignar);
        btnAsignar.setBounds(100, 200, 110, 30);

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(100, 240, 110, 30);

        btnSalir.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalir);
        btnSalir.setBounds(100, 280, 110, 30);
        getContentPane().add(txtTit);
        txtTit.setBounds(180, 160, 90, 28);

        jLabel4.setFont(new java.awt.Font("Arial", 1, 15)); // NOI18N
        jLabel4.setText("Titulo Obtenido:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(50, 170, 130, 18);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-321)/2, (screenSize.height-355)/2, 321, 355);
    }// </editor-fold>//GEN-END:initComponents

    private void txtCedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCedActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCedActionPerformed

    private void btnAsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAsignarActionPerformed
        // TODO add your handling code here:
         if(validarVacios())
            if(validarCedula()){
                    Profesor e = new Profesor();
                    e.setCedula(Integer.parseInt(txtCed.getText()));
                    e.setNombre(txtNom.getText());
                    e.setApellido(txtApe.getText());
                    e.setTitulo(txtTit.getText());
                    seccion.setProfesorseccion(e);
                    JOptionPane.showMessageDialog(new JFrame(),"Profesor asignado","Profesor",JOptionPane.INFORMATION_MESSAGE);
                    cancelar();
                }
            else
                JOptionPane.showMessageDialog(new JFrame(),"Cedula invalida","Profesor",JOptionPane.WARNING_MESSAGE);
        else
            JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Profesor",JOptionPane.WARNING_MESSAGE);

}//GEN-LAST:event_btnAsignarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        cancelar();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        dispose();
}//GEN-LAST:event_btnSalirActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormularioProfesor().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAsignar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField txtApe;
    private javax.swing.JTextField txtCed;
    private javax.swing.JTextField txtNom;
    private javax.swing.JTextField txtTit;
    // End of variables declaration//GEN-END:variables

}
